package activity

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"
	"gitee.com/liuxuezhan/ar-platform/admin-api/pkg/code"
	"gitee.com/liuxuezhan/ar-platform/rpc-client/setting/client/activityinfo"
	"github.com/zeromicro/go-zero/core/logc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ActivityInfoLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 详情
func NewActivityInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ActivityInfoLogic {
	return &ActivityInfoLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ActivityInfoLogic) ActivityInfo(req *types.ActivityInfoReq) (resp *types.ActivityInfoListItemRes, err error) {
	u, err := l.svcCtx.SettingService.Activity.ActivityInfo(l.ctx, &activityinfo.ActivityInfoReq{Id: req.Id, MerchantId: 1})

	if err != nil {
		logc.Error(l.ctx, "ActivityInfo err:", err)
		return nil, err
	}

	if u.Code != int64(code.SettingRpcSuccessful.Code()) {
		return resp, code.BusinessFailure
	}

	if u.Data.Id == 0 {
		return nil, code.NotData
	}

	return &types.ActivityInfoListItemRes{
		Id:          u.Data.Id,
		MerchantId:  u.Data.MerchantId,
		Title:       u.Data.Title,
		JumpType:    u.Data.JumpType,
		Status:      int64(u.Data.Status),
		Cover:       u.Data.Cover,
		ActivityPic: u.Data.ActivityPic,
		Sort:        u.Data.Sort,
	}, nil
}
